package strategy;

import java.util.Scanner;
import java.util.function.DoubleToIntFunction;

public class StrategyMain {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double price = 0d; // 商品单价
        int num = 0; // 商品购买数量
        double totalPrices = 0d; // 当前商品消费总计
        double total = 0d; // 总消费

        do {
            System.out.println("选择商品消费模式：[1]原价, [2]八折, [3]七折, [0]退出");
            System.out.print("> ");
            int discount = sc.nextInt();
            if(discount == 0) break;
            System.out.print("输入商品价格：");
            price = sc.nextDouble();
            System.out.print("输入商品数量：");
            num = sc.nextInt();

            // 使用工场模式创建 CashStrategy 对象
            //CashStrategy cs = CashFactory.createCashAccess(discount);
            //totalPrices = cs.acceptCash(price, num);

            // 使用工厂模式创建 CashContext 对象
            CashContext cc = CashContextFactory.createCashAccess(discount);
            totalPrices = cc.getResult(price, num);

            total += totalPrices;
            System.out.println("[总消费]" + total);
        } while (price > 0 && num > 0);
    }
}
